package cn.edu.nwsuaf.examcenter.controller;

import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import cn.edu.nwsuaf.examcenter.pojo.College;
import cn.edu.nwsuaf.examcenter.pojo.Major;
import cn.edu.nwsuaf.examcenter.service.CollegeService;
import cn.edu.nwsuaf.examcenter.service.MajorService;

/****
 * 专业控制器，用于控制专业页面数据流向以及页面条钻
 * @author Fantacy
 *
 */
@Controller
@RequestMapping(value="/major")
public class MajorController {
	@Resource(name="majorService")
	private MajorService majorService;
	
	@Resource(name="collegeService")
	private CollegeService collegeService;
	
	/****
	 * 搜索专业信息
	 * @param key
	 * @param p
	 * @param modelMap
	 * @return
	 */
	@RequestMapping(value="/loadMajor")
	public String laodMajor(@RequestParam(value="key",required=false)String key, @RequestParam(value="p",required=false)String p, ModelMap modelMap){
		majorService.loadMajor(modelMap);
		return "exam/major-list";
	}
	
	/*加载学院信息*/
	@ResponseBody
	@RequestMapping(value="/json/loadCollege")
	public List<College> jsonLoadCollege(){
		return collegeService.jsonLoadCollege();
	}
	
	/****
	 * 添加专业
	 * @param major
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value="/addMajor",method=RequestMethod.POST)
	public String addMajor(@ModelAttribute Major major){
		return majorService.addMajor(major);
	}
	
	/***
	 * 单个专业信息删除
	 * @param majorNo
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value="/deleteMajor/{majorNo}")
	public String deleteMajor(@PathVariable(value="majorNo")String majorNo){
		return majorService.deleteMajor(majorNo);
	}
	
	/****
	 * 批量删除专业信息
	 * @param array
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value="/deleteMajorList")
	public String deleteMajorList(@RequestParam(value="array")String array){
		return majorService.deleteMajorList(array);
	}
	
	/****
	 * 导出专业信息
	 * @param request
	 * @param response
	 */
	@RequestMapping(value="/exportMajor")
	public void exportMajor(HttpServletRequest request, HttpServletResponse response){
		majorService.exportMajor(request, response);
	}
}
